﻿using Finance.Web.Models;
using Finance.Web.Models.Accounting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Finance.Web.Controllers
{
    public class AccountingController : Controller
    {
        public ActionResult Index()
        {
            return PartialView();
        }

        public ActionResult Deposites()
        {
            return PartialView();
        }

        public ActionResult Effect()
        {
            return PartialView();
        }

        public ActionResult Yield()
        {
            return PartialView();
        }

        public ActionResult Amount()
        {
            return PartialView();
        }

        public ActionResult Calculate(DepostAccounting model)
        {
            if (ModelState.IsValid)
            {
                double [] byMonth;
                double amount = new DepositAmountAccounting().Calculate(model, out byMonth);
                return Json(new {amount= amount, byMonth = byMonth });
            }
            return Utils.AngularFormErrors(this);
        }

        public ActionResult CalculateEffect(DepostAccounting model)
        {
            if (ModelState.IsValid)
            {
                return Json(new EffectDepositAccounting().Calculate(model));
            }
            return Utils.AngularFormErrors(this);
        }

        public ActionResult CalculateYieldPeriod(DepostAccounting model)
        {
            if (ModelState.IsValid)
            {
                return Json(new YieldDepositAccounting().CaclulatePeriodYield(model));
            }
            return Utils.AngularFormErrors(this);
        }

        public ActionResult CalculateYieldYear(DepostAccounting model)
        {
            if (ModelState.IsValid)
            {
                return Json(new YieldDepositAccounting().CaclulateYearYield(model));
            }
            return Utils.AngularFormErrors(this);
        }

        public ActionResult CalculateAmount(DepostAccounting model)
        {
            if (ModelState.IsValid)
            {
                return Json(new DepositAmountAccounting().CalculateAmount(model));
            }
            return Utils.AngularFormErrors(this);
        }
    }
}
